﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace M3G {
    public abstract  class Texture : Transformable
    {
        #region Constant
        // フィルター方式
        public const int FilterBaseLevel   = 208;
        public const int FilterLinear      = 209;
        public const int FilterNearest     = 210;
        public const int FilterAnisotropic = 211;
        #endregion

        #region Field
        ImageBase imageBase;
        int       imageFilter;
        int       levelFilter;
        #endregion

        #region Method
        public Texture (ImageBase imageBase) {
            if (imageBase == null) {
                throw new ArgumentNullException ("Image is null");
            }

            this.imageBase   = imageBase;
            this.imageFilter = FilterNearest;
            this.levelFilter = FilterBaseLevel;
        }

        protected Texture (Texture texture)
            : base (texture) {
            this.imageBase   = texture.imageBase;
            this.imageFilter = texture.imageFilter;
            this.levelFilter = texture.levelFilter;
        }

        public ImageBase ImageBase {
            get { return imageBase; }
        }

        protected void SetImageBase (ImageBase image) {
            this.imageBase = image;
        }

        public int ImageFilter {
            get { return imageFilter; }
        }

        public int LevelFilter {
            get { return levelFilter; }
        }

        public void SetFiltering(int levelFilter, int imageFilter)
        {
            if (levelFilter < FilterBaseLevel || levelFilter > FilterLinear) {
                throw new ArgumentException ("Level filter must be BaseLevel, Linear, Nearest, filter=" + levelFilter);
            }
            if (imageFilter < FilterLinear || imageFilter > FilterAnisotropic) {
                throw new ArgumentException ("Image filter must be Linear,Near, Anisotropic, filter=" + imageFilter);
            }

            this.levelFilter = levelFilter;
            this.imageFilter = imageFilter;
        }

        public override Object3D[] References {
            get {
                var q = new List<Object3D> ();
                q.AddRange (base.References);
                q.Add (imageBase);
                q.RemoveAll (x => x == null);
                return q.ToArray ();
            }
        }

        #endregion

    }
}
